package zx.com.camratest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import tcking.github.com.giraffeplayer.GiraffePlayer;
import tcking.github.com.giraffeplayer.GiraffePlayerView;

public class Main2Activity extends AppCompatActivity {
    private GiraffePlayer player;//播放视频界面

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        initData();
        Button play_btn = (Button) findViewById(R.id.play_btn);
        play_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                EditText utl_et = (EditText) findViewById(R.id.utl_et);
                player.play(utl_et.getText().toString());
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (player != null) {
            player.onResume();
        }
    }

    @Override
    protected void onPause() {
        if (player != null) {
            player.onPause();
        }
        super.onPause();
    }

    @Override
    protected void onStop() {
        if (player != null) {
            player.stop();
        }
        super.onStop();
    }


    private void initData() {
        player = new GiraffePlayer(this);
        player.setErrorCallBack(callBack);
        player.setScaleType(GiraffePlayerView.SCALETYPE_FILLPARENT);
        player.hideBottomUI();
    }

    //播放器播放失败回调
    private GiraffePlayer.ErrorCallBack callBack = new GiraffePlayer.ErrorCallBack() {
        @Override
        public void cantPlayer() {

        }
    };

}
